Skip to content

EMRY-006: EventBus pub/sub fan-out (bounded, drop-and-count) - #54

Merged
vxfemboy merged 2 commits into
mainfrom
emry-006-event-bus
Jun 25, 2026
Merged

vxfemboy merged 2 commits into
mainfrom
emry-006-event-bus

Conversation

@vxfemboy

Copy link
Copy Markdown
Member

Closes EMRY-006 (#7). Branched off main. Completes M0.

What

crates/emry-core/src/bus.rs — EventBus multi-subscriber fan-out over crossbeam_channel. subscribe() returns an independent Receiver; publish(&Event) clones to each live subscriber and never blocks.

Backpressure (review-driven)

Per-subscriber channels are bounded (DEFAULT_SUBSCRIBER_CAPACITY = 16 384) with try_send: a stalled observer (e.g. wedged TUI render) has events dropped and counted (dropped()) instead of growing memory without limit — mirroring the ring buffer policy and the project's 'never harm the run' ethos. Disconnected receivers are pruned.

Verification

  • ./scripts/pre-commit-rust.sh green: fmt, clippy -D warnings, tests, bus.rs 98% lines
  • Tests: 2 subscribers × 100 events in order, no-sub no-op, full-queue drop+count, dead-subscriber pruning, cross-thread delivery

Review notes

  • Took the reviewer's unbounded-growth finding (conf 95) → switched to bounded + drop-count.
  • Kept the lock across fan-out (sends are wait-free try_send; engine drains on one thread) and documented the trade-off rather than adding a per-publish sender-list clone.

vxfemboy added 2 commits June 24, 2026 21:45
Multi-subscriber fan-out over crossbeam unbounded channels: subscribe()
returns an independent Receiver; publish(&Event) clones to each live
subscriber, prunes dropped ones, and never blocks on a slow observer.
Send+Sync for sharing behind Arc. Tests: 2 subscribers x 100 events in
order, no-sub no-op, dead-subscriber pruning, cross-thread delivery.
Switch per-subscriber channels from unbounded to bounded(DEFAULT_SUBSCRIBER_
CAPACITY=16_384) with try_send: a stalled subscriber has events dropped and
counted (dropped()) rather than growing memory without limit, matching the
ring buffer's backpressure policy. Disconnected receivers still pruned.
@vxfemboy
vxfemboy merged commit 1a69752 into main Jun 25, 2026
3 checks passed
@vxfemboy
vxfemboy deleted the emry-006-event-bus branch June 25, 2026 01:49
@vxfemboy vxfemboy mentioned this pull request Jun 25, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant